package org.example.config;

import com.rabbitmq.client.*;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
//参数：要监听的队列，获取消息
//@RabbitListener(queues = "queuedemo1")
public class MqConfig {

    /*final String QUERE_NAME="simp_queue";

    @RabbitListener(queues = "QUEUE_DELAY")
    //MQ消息处理
    @RabbitHandler
    public void handleMessage1(String message){
        System.out.println("QUEUE_DELAY队列接收到的消息："+message);
    }

    @RabbitListener(queues = "queuedemo2")
    //MQ消息处理
    @RabbitHandler
    public void handleMessage2(String message){
        System.out.println("queuedemo2队列接收到的消息："+message);
    }*/

    /*@RabbitListener(queues = "simp_queue")
    public void test2() throws Exception {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUERE_NAME,false,false,false,null);
        DefaultConsumer defaultConsumer = new DefaultConsumer(channel){
            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                String exchange = envelope.getExchange();
                System.out.println(exchange);
                long deliveryTag = envelope.getDeliveryTag();
                String msg = new String(body, "utf-8");
                System.out.println(msg);
                channel.basicAck(envelope.getDeliveryTag(),false);
            }
        };
        channel.basicConsume(QUERE_NAME, false, defaultConsumer);
    }*/
}